package com.zzptc.shop.servlet;

import com.zzptc.shop.dao.IDAO;
import com.zzptc.shop.dao.NewsDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "NewsServlet")
public class NewsServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        List list=new ArrayList();
        IDAO idao=new NewsDao();
        try {
            list=idao.getAll();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        HttpSession session=request.getSession();
        session.setAttribute("news",list);

        request.getRequestDispatcher("/index.jsp").forward(request,response);


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
